
#include "Main.h"

#include "MathsHelper.h"

#include <math.h>

u_int MathsHelper::RGBAtoABGR ( const u_int uColour )
{
	unsigned char ucRed		= static_cast<unsigned char>(uColour  >> 24 );
	unsigned char ucGreen	= static_cast<unsigned char>(uColour >> 16 );
	unsigned char ucBlue	= static_cast<unsigned char>(uColour >> 8 );
	unsigned char ucAlpha	= static_cast<unsigned char>(uColour);

	u_int uReturn = 0x00000000;

	uReturn |= ( ucRed );
	uReturn |= ( ucGreen << 8 );
	uReturn |= ( ucBlue << 16 );
	uReturn |= ( ucAlpha << 24 );
	return uReturn;
}

u_int MathsHelper::InterpolateColour ( const u_int uCol1, const u_int uCol2, float fFraction)
{
	unsigned char ucRed1	= static_cast<unsigned char>(uCol1  >> 24 );
	unsigned char ucGreen1	= static_cast<unsigned char>(uCol1 >> 16 );
	unsigned char ucBlue1	= static_cast<unsigned char>(uCol1 >> 8 );
	unsigned char ucAlpha1	= static_cast<unsigned char>(uCol1);

	unsigned char ucRed2	= static_cast<unsigned char>(uCol2  >> 24 );
	unsigned char ucGreen2	= static_cast<unsigned char>(uCol2 >> 16 );
	unsigned char ucBlue2	= static_cast<unsigned char>(uCol2 >> 8 );
	unsigned char ucAlpha2	= static_cast<unsigned char>(uCol2);

	const unsigned char ucRed	= static_cast< unsigned char >( static_cast<float>( ucRed1 ) + static_cast<float>( ucRed2 - ucRed1  ) * fFraction );
	const unsigned char ucGreen	= static_cast< unsigned char >( static_cast<float>( ucGreen1 ) + static_cast<float>( ucGreen2 - ucGreen1  ) * fFraction );
	const unsigned char ucBlue	= static_cast< unsigned char >( static_cast<float>( ucBlue1 ) + static_cast<float>( ucBlue2 - ucBlue1  ) * fFraction );
	const unsigned char ucAlpha	= static_cast< unsigned char >( static_cast<float>( ucAlpha1 ) + static_cast<float>( ucAlpha2 - ucAlpha1  ) * fFraction );
	
	u_int uReturn = 0x00000000;

	uReturn |= ( ucRed << 24 );
	uReturn |= ( ucGreen << 16 );
	uReturn |= ( ucBlue << 8 );
	uReturn |= ( ucAlpha );

	return uReturn;
}

// eof
